package com.String;

/*
String 的方法
*/
public class Demo02 {
    public static void main(String[] args) {
        String str = "asdfghjklgfdssad";
        //获取字符串的长度
        int longth = str.length();
        System.out.println(longth);
        //获取字符串对应索引的元素
        char indecx = str.charAt(6);
        System.out.println(indecx);
        //把字符串转为字符数组
        char[] arr = str.toCharArray();
        System.out.println(arr);
        //判断字符串是否一样
        boolean b = str.equals("asdfghjklgfdssad");
        System.out.println(b);
        //判断字符串是否一样，忽略大小写
        boolean b2 = str.equalsIgnoreCase("AsdfghjKlgfdSsad");
        System.out.println(b2);
        //截取字符串
        String s = "欢迎李文建同学来到黑马学习！李文建";
        String resout = s.substring(2, 5);
        System.out.println(resout);
        //截取字符串从一个位置直到最后
        String resout2 = s.substring(5);
        System.out.println(resout2);
        //替换字符串
        String resout3 = s.replace("李文建", "lwj");
        System.out.println(resout3);
        //判断字符串是否包含指定内容
        boolean resout4 = s.contains("李文建");
        System.out.println(resout4);
        //indexof()查询第一次出现位置的索引
        int index1 = s.indexOf("李文建");
        System.out.println(index1);
        //查找做后一次查找字符串的位置
        int index2 = s.lastIndexOf("李文建");
        System.out.println(index2);

        String s2 = "李文建";
        //判断是否以某个字开头
        boolean r1 = s2.startsWith("李");
        System.out.println(r1);
        //判断是否以某个字结尾
        boolean r2 = s2.endsWith("建");
        System.out.println(r2);

        String s3 = "aaa.bbb.ccc.ddd";
        //切割某个字符
        //当字符串以.分割时,分割时候有用\\.来区分
        String[] arr2 = s3.split("\\.");
        for (int i = 0; i < arr2.length; i++) {
            System.out.println(arr2[i]);
        }
    }
}
